from django.shortcuts import render, redirect
from XinYuWIT.models import HCL32, SDS, SAS, SCL90, User
import json



def index(request):
    return render(request, "index.html", {})

def hcl_32(request):
    return render(request,"HCL-32.html")

def sas(request):
    return render(request,"SAS.html")

def scl_90(request):
    return render(request,"SCL-90.html")

def sds(request):
    return render(request,"SDS.html")

def stresspoint(request):
    return render(request,"StressPoint.html")

def get_score(request):
    if request.method == "POST":
        info = request.session.get('info')
        user = User.objects.get(id=info.get('id'))
        if user.is_authenticated:

            data = json.loads(request.body)
            score = data.get("score")
            test_name = data.get("test_name")
            print(score, test_name)
            match test_name:
                case "HCL-32":
                    HCL32.objects.create(score = float(score), user = user)
                case "SAS":
                    SAS.objects.create(score = float(score), user = user)
                case "SCL-90":
                    SCL90.objects.create(score = float(score), user = user)
                case "SDS":
                    SDS.objects.create(score = float(score), user = user)

        return redirect("/test/")
